package com.example.mvp.view;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.IdRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.BarUtils;
import com.example.mvp.R;
import com.example.mvp.presenter.IPresenter;

public abstract class BaseActivity<P extends IPresenter> extends AppCompatActivity implements IView, IActivity {
    protected P mPresenter;

    //创建
    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());

        initView();
//        getLifecycle().addObserver(mPresenter);
        initData();
    }

    public void status_show(int color){
        //修改状态栏当中的图片及文字颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            //把状态栏标记为浅色，然后状态栏的字体颜色自动转换为深色
        }

        BarUtils.setStatusBarColor(this, color);
        //添加让出状态栏高度->防止contentView布局绘制到状态栏上
        BarUtils.addMarginTopEqualStatusBarHeight(addStatusView());
    }

    public abstract View addStatusView();

    //销毁
    @Override
    protected void onDestroy() {
        super.onDestroy();
        getLifecycle().removeObserver(mPresenter);
    }

    //统计日志信息
    @Override
    protected void onResume() {
        super.onResume();
//        MobclikAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        MobclikAgent.onPause(this);
    }

    @Override
    public void startPage(Bundle bundle,Class clazz) {
        Intent intent = new Intent(this,clazz);
        if (bundle != null){
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    public void startPage(Class clazz) {
        startPage(null,clazz);
    }


    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, ""+msg, Toast.LENGTH_SHORT).show();
    }
}

